package com.github.hanlyjiang.androidtemplate.opengl.airhockey;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.widget.Toast;

/**
 * Created by HanlyJiang on 2016/11/26.
 */

public class AirHockeyOpenGLActivity extends Activity {

    private boolean renderset = false;
    private GLSurfaceView mGlView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mGlView = new GLSurfaceView(this);
        setContentView(mGlView);

        //
        boolean supportES2 = isSupportsGLES2();
        if(supportES2){
            //
            mGlView.setEGLContextClientVersion(2);

            //
            mGlView.setRenderer(new AirHockeyRender(this));
            renderset = true;
        }else {
            Toast.makeText(this,"设备不支持OpenGL ES 2.0",Toast.LENGTH_SHORT).show();
            return;
        }




    }


    @Override
    protected void onPause() {
        super.onPause();
        if(renderset) {
            mGlView.onPause();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(renderset){
            mGlView.onResume();
        }
    }

    private boolean isSupportsGLES2() {
        final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
        return configurationInfo.reqGlEsVersion >= 0x20000;
    }
}
